﻿using CodeCity.Common;
using CodeCity.UserManagement.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeCity.UserMangament.Repository
{
    public class HumanRepository : RepositoryBase<Human>
    {
        public HumanRepository(GameDbContext gameDbContext) : base(gameDbContext)
        {
        }

        public Task<bool> ExistAsync(long unitId)
        {
            return Query.AnyAsync(x => x.UnitId == unitId);
        }

        public Task<List<Human>> LoadALlAsync()
        {
            return Query.ToListAsync();
        }

        public override Task<int> CountAsync()
        {
            return Query.Where(x => !x.IsDead).CountAsync();
        }

        public Task<int> CountTodayAsync()
        {
            return Query.Where(x => !x.IsDead).Where(x => x.BirthDay.Date == GameDateTime.Now.Date).CountAsync();
        }

        public Task<Human> GetByUnitIdAsync(long humanId)
        {
            return Query.Where(x => x.UnitId == humanId).FirstOrDefaultAsync();
        }
    }
}
